package org.action.service.impl;


import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.action.domain.entity.Action;
import org.action.domain.pojo.action.ActionDetails;
import org.action.domain.pojo.action.ActionList;
import org.action.mapper.ActionMapper;
import org.action.service.IActionService;
import org.museum.api.client.ActionInventoryClient;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zafkiel
 * @since 2025-06-21
 */
@Service
public class ActionServiceImpl extends ServiceImpl<ActionMapper, Action> implements IActionService {

    @Autowired
    private ActionInventoryClient actionInventoryClient;
    @Override
    public List<ActionList> getaAllActionlist() {
        List<Action> actions=lambdaQuery().list();
        List<Integer> actionIds=actions.stream().map(Action::getId).toList();
        System.out.println( actionIds);
        List<Double> prices= (List<Double>) actionInventoryClient.getActionTicketPriceByIds(actionIds).get("data");
        System.out.println( prices);
        List<ActionList> res=new ArrayList<>();
        for(int i=0;i<actions.size();i++){
            ActionList actionList= BeanUtil.toBean(actions.get(i),ActionList.class);
            actionList.setAcTicketPrice(prices.get(i));
            res.add(actionList);
        }
        return res;
    }

    @Override
    public ActionDetails getActionDetailsById(Integer id) {
        List<Double> prices= (List<Double>) actionInventoryClient.getActionTicketPriceByIds(Arrays.asList(id)).get("data");
        ActionDetails actionDetails= BeanUtil.toBean(baseMapper.selectById(id),ActionDetails.class);
        actionDetails.setAcTicketPrice(prices.getFirst());
        return actionDetails;
    }
}
